<?php


namespace app\month\business;


use app\api\server\Token;
use app\month\model\User;

class UserBusiness
{

    /**
     * 判断用户是否注册
     * @param $openid
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function login($openid){
        $res = User::where('openid','=',$openid)->find();
        if (!$res) {
            # 没有注册过

            $res = User::create(['openid' => $openid]);
        }

        $uid = $res->id;

        return Token::createToken($uid);
    }

}